-- hp_trans_attack
-- created by zhuangsl
-- 每增加xx点生命，攻击提升

return {
    -- 返回的是提升的攻击点数
    apply = function(prop, baseValue)
        return prop[3];
    end,

    trigger = function(who, prop, value)
        -- 必须是玩家
        if who.type ~= OBJECT_TYPE_USER then
            return 0;
        end

        -- 出战宠物
        local pet = who:getActivePet();
        if not pet then
            return 0;
        end

        -- 计算进入迷宫时的基础生命值，取宠物生命值加上天赋附加的生命值
        local baseHp = pet:getMaxHp();
        -- 阵营天赋加成
        local classId = pet.classId;
        local campId = CampM.getPetCamp(classId)
        local p = PropM.combine(who, "camp_max_hp", campId);
        baseHp = PropM.apply(p, baseHp);
        -- TODO: 剑士天赋特殊处理一下
        pet = PetM.getMyPet(2);
        if pet then
            local rank = pet:getRank() or 0;
            baseHp = baseHp + 5 * rank;
        end

        -- 增加的生命值总量
        local addonHp = who:queryAttrib("max_hp") - baseHp;
        addonHp = math.max(addonHp, 0);
        -- 增幅的对应属性值
        local value = tonumber(prop[2]);
        if value > 0 then
            local times = math.modf(addonHp / value);
            local temp  = ME.user.dbase:queryTemp("hp_trans_attack", 0);

            -- 增幅的最终属性值
            value = prop[3] * times;

            -- 生命增幅攻击，触发特技发动特效
            ME.user.dbase:setTemp("hp_trans_attack", times);
            if times > temp then
                EventMgr.fire(event.SPECIAL_SKILL_TRIGGER, { propId = prop[1] });
            end
        else
            value = 0;
        end

        return value;
    end,

    record = function(target, prop, path)
        return false;
    end
};